# 使用(while或者do-while或者for实现以下功能)

# 1. 打印100个*
# i = 1
# while i<=100:
#     print("*")
#     i += 1

# 2. 让用户输入一个正整数放到变量n中,然后计算1+2+...+n,打印输出结果

# n = int(input("请输入一个正整数："))
# i =0
# sum = 0
# while i<=n:
#     sum += i
#     i += 1
# else:
#     print(f"1+2+...+n={sum}")

# 3. 打印1~500 数字之间用逗号分隔

# i = 1
# while i<=500:
#     print(f"{i}",end=",")
#     i += 1

# 4. 打印-100,-98,-96,...,-2,0

# i = -100
# while i<=0:
#     print(f"{i}",end=",")
#     i += 2

# 5. 计算1*2*...*10

# i = 1
# sum = 1
# while i<=10:
#     sum *= i
#     i += 1
# else:
#     print(f"{sum}")

# 6. 让用户输入一个数字n，打印n个*

# n = int(input("请输入一个数字："))
# i = 1
# while i<=n:
#     print("*")
#     i += 1

# 7. 将用户输入的一个数字，逆序输出

# n = int(input("请输入一个数字："))
# i = n
# while i>=0:
#     print(f"{i}",end=",")
#     i -= 1

# 8. 让用户输入数字n,打印:1 2 4 8 16 32 64 128 256 ... 2^n

# n = int(input("请输入一个数字："))
# i = 1
# while i<=2**n:
#     print(f"{i}",end="\t")
#     i *= 2

# 9. 让用户输入数字n,打印:0 1 4 9 16 25 ... n^2   提示：系统数学函数Math.pow()

# n = int(input("请输入一个数字："))
# i = 0
# m = 0
# l = 0
# while l<=n**2:
#     print(f"{l}",end="\t")
#     i += 1
#     m += 1
#     l = i * m

# 10. 打印-10.0,-9.9,-9.8,... ,9.9,10.0

# i = -10.0
# while i<=10.0:
#     print("%.1f" % i ,end=",")
#     i += 0.1

# 11. 一个球从100米高度自由下落，每次落地后反弹高度为原高度一半,再次落下
# 	*求它在第10次落地时，共经过多少米?
#   * 第10次反弹多高?
# (解题:先在纸上画一下，分析第一次、第二次，第三次是什么情况,分析规律)

# height = 100
# length = 0
# for i in range(1,11):
#     length += height*2
#     height /= 2
# length -= 100
# print(f"第十次落地时共经历：{length}米")
# print(f"第十次反弹反弹的高度：{height}米")

# 12. 遍历判断所有三位数是否水仙花数，输出他们。
# （所谓遍历（Traversal），字面意思是遍历就是全部走遍，到处周游的意思。）
# for bai in range(1,10):
#     for shi in range(0,10):
#         for ge in range(0,10):
#             sum = bai * 100 + shi * 10 + ge
#             if sum==bai*bai*bai+shi*shi*shi+ge*ge*ge:
#                 print(sum,end="\t")

# 13.打印如下图形:
# 13.1)
# *
# **
# ***
# ****
# *****

# for i in range(1,6):
#     for j in range(1,i+1):
#         print("*",end="")
#     print()

# 13-2)			i		*的数量
#  *****		0		5
#  ****			1		4
#  ***			2		3
#  **			3		2
#  *			4		1

# for i in range(1,6):
#     for j in range(1,7-i):
#         print("*",end="")
#     print()

# 13-3)			    i		空格		星
# 	       *		0		4		1
# 	      **		1		3		2
# 	     ***		2		2		3
# 	    ****		3		1		4
# 	   *****	    4		0		5

# for i in range(1,6):
#     for j in range(1,6-i):
#         print(" ",end="")
#     for k in range(1,i+1):
#         print("*",end="")
#     print()
#
# 13-4)
# 	*****
# 	 ****
# 	  ***
# 	   **
# 		*
# for i in range(1,6):
#     for j in range(1,i):
#         print(" ",end="")
#     for k in range(1,7-i):
#         print("*",end="")
#     print()

# 13-5)
# 		//     *
# 		//    ***
# 		//   *****
# 		//  *******
# 		//   *****
# 		//    ***
# 		//     *
# for i in range(1,5):         #控制上半行
#     for j in range(1,5-i):   #控制左侧
#         print(" ",end="")
#     for k in range(1,i*2):   #控制中间
#         print("*",end="")
#     for l in range(1,5-i):   #控制右侧
#         print(" ",end="")
#     print()
# for i in range(1,4):        #控制下半行
#     for j in range(1,i+1):
#         print(" ",end="")
#     for k in range(1,8-2*i):
#         print("*",end="")
#     for l in range(1,i+1):
#         print(" ",end="")
#     print()

# 13-6)
# 		//    *
# 		//   * *
# 		//  *   *
# 		// *     *
# 		//  *   *
# 		//   * *
# 		//    *
# for i in range(1,2):              #控制第一行
#     for j in range(1,5-i):
#         print(" ",end="")
#     for k in range(1,i+1):
#         print("*",end="")
#     for l in range(1,4-i):
#         print(" ",end="")
#     print()
# for i in range(1,4):              #控制2-4行
#     for j in range(1,4-i):
#         print(" ",end="")
#     for k in range(1,2):
#         print("*",end="")
#     for l in range(1,i*2):
#         print(" ",end="")
#     for m in range(1,2):
#         print("*",end="")
#     for n in range(1,4-i):
#         print(" ",end="")
#     print()
# for i in range(1,3):              #控制5-6行
#     for j in range(1,i+1):
#         print(" ",end="")
#     for k in range(1,2):
#         print("*",end="")
#     for l in range(1,6-i*2):
#         print(" ",end="")
#     for m in range(1,2):
#         print("*",end="")
#     for n in range(1,i+1):
#         print(" ",end="")
#     print()
# for i in range(1,2):               #控制最后一行
#     for j in range(1,5-i):
#         print(" ",end="")
#     for k in range(1,i+1):
#         print("*",end="")
#     for l in range(1,4-i):
#         print(" ",end="")
#     print()

# 13-7) 输入n(>=3) 打印出n行大小的实心菱形
# n = int(input("请输入一个数字："))
# if n%2==0:
#     for i in range(1, int(n/2+1)):         # 控制上半行
#         for j in range(1, int((n/2+1) - i+1)):
#             print(" ", end="")
#         for k in range(1, i * 2):
#             print("*", end="")
#         for l in range(1, int((n/2+1) - i+1)):
#             print(" ", end="")
#         print()
#     for i in range(1, int(n/2+1)):  # 控制下半行
#         for j in range(1, i + 1):
#             print(" ", end="")
#         for k in range(1, int(n+1) - 2 * i +1 ):
#             print("*", end="")
#         for l in range(1, i + 1):
#             print(" ", end="")
#         print()
# else:
#     for i in range(1, int((n+3)/2)):  # 控制上半行
#         for j in range(1, int((n+3)/2 - i)):  # 控制左侧
#             print(" ", end="")
#         for k in range(1, i * 2):  # 控制中间
#             print("*", end="")
#         for l in range(1, int((n+3)/2 - i)):  # 控制右侧
#             print(" ", end="")
#         print()
#     for i in range(1, int((n-1)/2+1)):  # 控制下半行
#         for j in range(1, i + 1):
#             print(" ", end="")
#         for k in range(1, int(n+1-2*i)):
#             print("*", end="")
#         for l in range(1, i + 1):
#             print(" ", end="")
#         print()

# 13-8) 输入n(>=3) 打印出n行大小的空心菱形
# n = int(input("请输入一个数字(>=3)："))
# if n % 2 == 1:
#     for i in range(1, 2):              # 控制第一行
#         for j in range(1, int((n+1)/2+1)):
#             print(" ", end="")
#         for k in range(1, 2):
#             print("*", end="")
#         for l in range(1, int((n+1)/2+1)):
#             print(" ", end="")
#         print()
#     for i in range(1, int((n+1)/2)):  # 控制上半部分（除去第一行）
#         for j in range(1, int((n+1-2*i)/2+1)):
#             print(" ", end="")
#         for k in range(1, 2):
#             print("*", end="")
#         for l in range(1, i * 2):
#             print(" ", end="")
#         for m in range(1, 2):
#             print("*", end="")
#         for o in range(1, int((n+1-2*i)/2+1)):
#             print(" ", end="")
#         print()
#     for i in range(1,int((n-1)/2)): # 控制下半部分（除去最后一行）
#         for j in range(1,i+2):
#             print(" ",end="")
#         for k in range(1,2):
#             print("*",end="")
#         for l in range(1,int(n-1-2*i)):
#             print(" ",end="")
#         for m in range(1,2):
#             print("*",end="")
#         for o in range(1,i+2):
#             print(" ",end="")
#         print()
#     for i in range(1, 2):             # 控制最后一行
#         for j in range(1, int((n+1)/2+1)):
#             print(" ", end="")
#         for k in range(1, 2):
#             print("*", end="")
#         for l in range(1, int((n+1)/2+1)):
#             print(" ", end="")
#         print()
# else:
#     for i in range(1,2):
#         for j in range(1,int((n-2)/2+1)):
#             print(" ",end="")
#         for k in range(1,2):
#             print("*",end="")
#         for l in range(1,int((n-2)/2+1)):
#             print(" ",end="")
#     print()
#     for i in range(1,int(n/2)):
#         for j in range(1,int(n/2-i)):
#             print(" ",end="")
#         for k in range(1,2):
#             print("*",end="")
#         for l in range(1,2*i):
#             print(" ",end="")
#         for m in range(1,2):
#             print("*",end="")
#         for o in range(1,int(n/2-i)):
#             print(" ",end="")
#         print()
#     for i in range(1,int(n/2)):
#         for j in range(1,i):
#             print(" ",end="")
#         for k in range(1,2):
#             print("*",end="")
#         for l in range(1,int(n-2*i)):
#             print(" ",end="")
#         for m in range(1,2):
#             print("*",end="")
#         for o in range(1,i):
#             print(" ",end="")
#         print()
#     for i in range(1,2):
#         for j in range(1,int((n-2)/2+1)):
#             print(" ",end="")
#         for k in range(1,2):
#             print("*",end="")
#         for l in range(1,int((n-2)/2+1)):
#             print(" ",end="")
#     print()


# 14) 用户输入一个数判断是不是素数
# 	质数（prime number）又称素数，有无限个。质数定义为在大于1的自然数中，除了1和它本身以外不再有其他因数，这样的数称为质数。
# n = int(input("请输入一个数（>=1）："))
# if n==1:
#     print("您输入得数字是一个素数")
# else:
#     for i in range(2,n):
#         if n%i==0:
#             print("您输入的数不是素数")
#             break
#         else:
#             i += 1
#             if i == n:
#                 print("您输入的数是一个素数")


# 15) 找出1~1000中找出依次所有个素数
# print("1",end=",")
# for i in range(2,1001):     # 这是遍历2-1000
#     for j in range(2,i):    # 这是判断是否是素数所需要的材料
#         if i%j==0:          # 这是具体判断是否是素数的判断式
#             break
#         else:
#             if j==i-1:
#                 print(f"{i}", end=",")
#

# 16) 在1~1000中找出依次找出50个素数 (break)
# 如何控制循环次数 或者是 控制循环截至 即 截至条件是有50个素数
# print("1",end=",")
# n = 1
# if n<=50:
#     for i in range(2, 1001):  # 这是遍历2-1000
#         for j in range(2, i):  # 这是判断是否是素数所需要的材料
#             if i % j == 0:  # 这是具体判断是否是素数的判断式
#                 break
#             else:
#                 if j == i - 1:
#                     print(f"{i}", end=",")
#                     n += 1

# 17) 抛出10次骰子，显示每次抛出的数字，如果得到6，显示你赢了，游戏结束。
# 如果抛了10次，都没抛出6，显示你输了
# import random
# for i in range(10):
#     n = random.randint(1, 6)
#     if n == 6:
#         print("你赢了，游戏结束")
#         break
#     else:
#         if i==9:
#             print("你输了，电脑获胜")
#             break

# 18) 抛在10次骰子，计算总和(如果抛出数字4，不计入总和)。(continue)

# import random
# sum = 0
# for i in range(10):
#     n = random.randint(1,6)
#     if n==4:
#         continue
#     else:
#         sum += n
# print(sum)

# 		// 综合练习:
# 		// 1. 编写一个猜拳游戏
# 		// 电脑使用随机函数出拳
# 		// 玩家出拳则由玩家输入 0 1 2
# 		// 玩家进入后可以选择游戏模式
# 		// 模式1 可以玩20次 (用for)
# 		// 模式2 可以一直玩到输20次为止(用while或者dowhile适合)
# 		// 游戏结束，统计输赢平局次数
# 		// 游戏结束，显示玩家的积分(赢得次数*10)
# 		// (提示: 先完成1局猜拳游戏。然后再加入更多功能)
# 		// 1. 玩家出拳
# 		// 2. 电脑出拳
# 		// 3. 显示输赢结果

# import random
#
# sel = int(input("请选择游戏模式：1玩10次，2一直玩到输20次为止："))
#
# win = 0
# lose = 0
# equal = 0
#
# handstr = ["石头","剪刀","布"]
#
# if sel==1:
#     print("模式1")
#     for i in range(20):
#         #出拳
#         p = int(input("请输入你出的拳（1石头2剪刀3布）:"))
#         c = random.randint(1,3)
#         print(f"玩家出的是{handstr[p-1]}")
#         print(f"电脑出的是{handstr[c-1]}")
#         # 比较结果
#         result = p-c
#         if result == 0:
#             equal += 1
#             print("平局")
#         elif result == -1 or result == 2:
#             print("玩家赢")
#             win += 1
#         else:
#             print("电脑赢")
#             lose += 1
#         print(f"第{i+1}次，赢{win}输{lose}平{equal}")
# else:
#     print("模式2")
#     i = 0
#     while lose<20:
#         #出拳
#         p = int(input("请输入你出的拳（1石头2剪刀3布）:"))
#         c = random.randint(1, 3)
#         # 比较结果
#         result = p - c
#         if result == 0:
#             equal += 1
#             print("平局")
#         elif result == -1 or result == 2:
#             print("玩家赢")
#             win += 1
#         else:
#             print("电脑赢")
#             lose += 1
#         i += 1
#         print(f"第{i + 1}次，赢{win}输{lose}平{equal}")
#